<div class="form">
<?php 
#print_r(AController::_user()->profile->attributes);
#print_r($model);
?>

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'article-form',
	'enableAjaxValidation'=>false,
	'htmlOptions' => array( 'enctype'=>'multipart/form-data' ),
)); ?>

	<p class="hint">Поля с <span class="required">*</span> обязательны для заполнения.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'alias'); ?>
		<?php echo $form->textField($model,'alias',array('size'=>60,'maxlength'=>45)); ?>
		<p class="hint">Часть ссылки. Использовать только английские буквы, цифры и дефис.</p>
		<?php echo $form->error($model,'alias'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'author'); ?>
		<?php 
			if($model->isNewRecord){
				echo CHtml::encode(Yii::app()->user->name);
				echo $form->hiddenField($model, 'author', array( 'value'=>Yii::app()->user->name ));
			} else {
				echo CHtml::encode($model->author);
				echo $form->hiddenField($model, 'author', array( 'value'=>$model->author ));
			}
			#echo $form->textField($model,'author',array('size'=>60,'maxlength'=>45, 'value'=>Yii::app()->user->name)); 
		?>
		<?php echo $form->error($model,'author'); ?>
	</div>
	
	<?php if(!$model->isNewRecord): ?>
	<div class="row">
		<?php echo $form->labelEx($model,'moderator'); ?>
		<?php 
			echo CHtml::encode(Yii::app()->user->name);
			echo $form->hiddenField($model, 'moderator', array( 'value'=>Yii::app()->user->name ));
		?>
		<?php echo $form->error($model,'author'); ?>
	</div>
	<?php endif; ?>

	<div class="row">
		<?php echo $form->labelEx($model,'publicated'); ?>
		<?php
		$this->widget('ext.timepicker.TimePicker', array(
			'id'=>'publicated',
			'model'=>$model,
			'name'=>'publicated',
			'options'=>array(
				'duration'=>'',
				'showTime'=>true,
				'time24h'=>true,
				'dateFormat'=>'yy-mm-dd',
				'firstDay' => 1,
				'stepMinutes'=>5,
				'showOn'=>'button',
				'changeMonth'=>true,
				'changeYear'=>true,
			),
		));
		?>
		<?php echo $form->error($model,'publicated'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'preamble'); ?>
		<?php
			$this->widget('ext.markitup.EMarkitUp', array(
					'id'=>'preamble',
					'model'=>$model,
					'name'=>'preamble',
					'options'=>array(
						'set'=>'markdown',
					),
				));
		?>
		<?php echo $form->error($model,'preamble'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'text'); ?>
		<?php
			/*$this->widget('ext.markitup.EMarkitUp', array(
					'id'=>'text',
					'model'=>$model,
					'name'=>'text',
					'options'=>array(
						'set'=>'markdown',
					),
				));*/
		?>
		
		<?php
		$this->widget('ext.markitup.EMarkitUp', array(
			'model'=>$model,
			'name'=>'text',
			'options'=>array(
				'data'=>array('preid'=>$model->preid),
				'imageUpload'=>true,
				'imageUploadUrl'=>CHtml::normalizeUrl(array('articles/uploadImage')),
			),
		));
		?>
		<?php echo $form->error($model,'text'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'_tag'); ?>
		<?php 
		$this->widget('ext.tags.ETags', array(
					'id'=>'_tag',
					'model'=>$model,
					'name'=>'_tag',
					'options'=>array(
					),
				));
		?>
		<?php echo $form->error($model, '_tag'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Создать' : 'Сохранить'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->